            <div style="margin: 20px">
                <h2>Scripts</h2>
                <span>Copy and paste this external script reference in your HTML document's header.</span><br />
                <br />
                <h4>Universal external reference</h4>
                <span>This script can be accessed from any HTML document with access to this domain.</span><br />
                <br />
                <form action="#" method="post">
                    <textarea readonly="readonly" cols="60" rows="2" style="width: 90%; max-width: 90%; min-width: 90%;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://itec.trevorsays.com/subpages/scripts/script.js&quot;&gt;&lt;/script&gt;</textarea>
                </form><br />
                <br />

                <h4>Local external reference</h4>
                <span>This script can be accessed on its own hosting. This will require placing the external script along with the HTML documents.</span><br />
                <br />
                <form action="#" method="post">
                    <textarea readonly="readonly" cols="60" rows="2" style="width: 90%; max-width: 90%; min-width: 90%;">&lt;script type=&quot;text/javascript&quot; src=&quot;script.js&quot;&gt;&lt;/script&gt;</textarea>
                </form>
                <br />

                <h4>Inline script</h4>
                <span>This script can be accessed within the header of a HTML document. This will consume the most bandwidth, as no caching is available.</span><br />
                <br />
                <form action="#" method="post">
                    <textarea readonly="readonly" cols="60" rows="30" style="width: 90%; max-width: 90%; min-width: 90%;">
var TRACKING = {
contextPath : '/tracker/',
eventStack : new Array(),

createEvent : function(type, payload, reference) {
    var event = new Object();
    if (!type || type == null || type == "")
        throw new NullPointerException('type');
    event.type = type;
    event.payload = payload;
    event.reference = reference;

    event.time = new Date();
    event.HTMLSender = this.getHTMLSender();
    event.session = this.getSession();

    TRACKING.eventStack[this.eventStack.length] = event;
    return event;
},

getHTMLSender : function() {
    var sender = new Object();
    sender.secure = location.protocol == 'https:';
    sender.hostName = location.host;
    sender.uri = location.pathname;
    sender.parameters = location.search;
    return sender;
},

getSession : function() {
    var session = getCookie('tr_cookie');
    if (session == undefined) {
        session = TRACKING.generateSession();
        setCookie('tr_cookie', session, 14);
    }
    return session;
},

generateSession : function() {
    var req = new XMLHttpRequest();
    var r;
    req.open('GET', this.contextPath + 'CreateSession', false);
    req.send();
    r = req.responseText;
    return r;
},
convertEventToXML : function(event) {
    xmlBody = '&lt;Event&gt;\n';
    xmlBody += ' &lt;Type&gt;&lt;EventName&gt;' + event.type + '&lt;/EventName&gt;&lt;/Type&gt;\n';
    xmlBody += ' &lt;HTMLSender&gt;\n';
    xmlBody += ' &lt;Secure&gt;' + event.HTMLSender.secure + '&lt;/Secure&gt;\n';
    xmlBody += ' &lt;HostName&gt;' + event.HTMLSender.hostName + '&lt;/HostName&gt;\n';
    xmlBody += ' &lt;URL&gt;' + event.HTMLSender.uri + '&lt;/URL&gt;\n';
    xmlBody += ' &lt;Parameters&gt;' + escape(event.HTMLSender.parameters) + '&lt;/Parameters&gt;\n';
    xmlBody += ' &lt;/HTMLSender&gt;\n';
    xmlBody += ' &lt;Session&gt;&lt;TokenID&gt;' + event.session + '&lt;/TokenID&gt;&lt;/Session&gt;\n';
    xmlBody += ' &lt;Payload&gt;' + escape(event.payload) + '&lt;/Payload&gt;\n';
    // 2006-08-29T01:18:15.001Z
    xmlBody += ' &lt;Time&gt;' + event.time.getFullYear() + '-';
    xmlBody += (((event.time.getMonth() + 1) + '').length == 1 ? '0' + (event.time.getMonth() + 1) : (event.time.getMonth() + 1)) + '-';
    xmlBody += ((event.time.getDate() + '').length == 1 ? '0' + event.time.getDate() : event.time.getDate()) + 'T';
    xmlBody += ((event.time.getHours() + '').length == 1 ? '0' + event.time.getDate() : event.time.getDate()) + ':';
    xmlBody += event.time.getMinutes() + ':';
    xmlBody += event.time.getSeconds() + '.';
    xmlBody += event.time.getMilliseconds() + '&lt;/Time&gt;\n';
    // xmlBody += '&lt;Reference&gt;' + event.reference + '&lt;/Reference&gt;';
    xmlBody += '&lt;/Event&gt;\n';
    return xmlBody;
},
commit : function() {
    if (this.retroUnload != undefined)
        this.retroUnload();

    var xmlBody = '&lt;?xml version="1.0"?&gt;\n';
    xmlBody += '&lt;Events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://' + location.hostname + ':' + location.port
            + TRACKING.contextPath + 'EventSchemaV3.xsd"&gt;';
    for (i = 0; i &lt; TRACKING.eventStack.length; i++) {
        xmlBody += TRACKING.convertEventToXML(TRACKING.eventStack[i]);
    }
    TRACKING.eventStack = new Array();
    xmlBody += '&lt;/Events&gt;';
    var req = new XMLHttpRequest();
    req.open('POST', TRACKING.contextPath + 'submit', true);
    req.setRequestHeader("Content-type", "text/xml");
    req.send(xmlBody);
}

            };

            // Source http://www.w3schools.com/js/js_cookies.asp
            // TODO: replace this.
            function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i &lt; ARRcookies.length; i++) {
    x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
    y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
    x = x.replace(/^\s+|\s+$/g, "");
    if (x == c_name)
        return unescape(y);
}
            };

            function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
            };
// End borrowed code.

// TODO: add routine updates

TRACKING.retroUnload = window.onbeforeunload;
window.onbeforeunload = TRACKING.commit;
                    </textarea>
                </form>
            </div>
